package com.wuhan.template.module.find.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseApplication;
import com.wuhan.template.base.BaseViewHolder;
import com.wuhan.template.base.MyBaseAdapter;
import com.wuhan.template.module.find.bean.AAA;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/10.
 */
public class ZhuantiListAdapter extends MyBaseAdapter<AAA.ListBean> {

    private Context mContext;
    private List<AAA.ListBean> listBeans;
    private final DisplayImageOptions options;

    public ZhuantiListAdapter(Context context, List<AAA.ListBean> list) {
        super(context, list);
        this.mContext = context;
        this.listBeans = list;
        options = new DisplayImageOptions
                .Builder()
                .cacheOnDisk(true)
                .cacheInMemory(true)
                .build();
    }

    @Override
    public int getLayoutId() {
        return R.layout.find_list_item;
    }

    @Override
    public BaseViewHolder getViewHolder() {
        return new MyBaseViewHolder();
    }

    @Override
    public void bindViews(View view, BaseViewHolder viewHolder) {

        MyBaseViewHolder holder = (MyBaseViewHolder) viewHolder;

        AAA.ListBean.IndexpicBean indexpic = listBeans.get(holder.position).getIndexpic();

        String picUrl = indexpic.getHost() + indexpic.getDir() + indexpic.getFilepath() + indexpic.getFilename();

        holder.imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        ((BaseApplication) mContext).getImageLoader().displayImage(picUrl, holder.imageView,options);

        String title = listBeans.get(holder.position).getTitle();

        holder.textView.setText(title);

    }

    class MyBaseViewHolder extends BaseViewHolder {

        @BindView(R.id.zt_image)
        ImageView imageView;
        @BindView(R.id.zt_title)
        TextView textView;

    }
}
